package org.ponly.cta4j.drawing.text.glyphsvisitor;

import org.ponly.cta4j.drawing.text.Glyphs;

import java.awt.geom.Rectangle2D;

/**
 * 水平间距.
 *
 * @author mag
 * @Date 6 mars 2008
 */
public class HorizontalSpaceGlyphsVisitor implements GlyphsVisitor {

    private int spaceBetweenGlyphs = 0;

    public HorizontalSpaceGlyphsVisitor(int spaceBetweenGlyphs) {
        this.spaceBetweenGlyphs = spaceBetweenGlyphs;
    }

    public void visit(Glyphs glyphs, Rectangle2D backgroundBounds) {
        for (int i = 1; i < glyphs.size(); i++) {
            double tx = glyphs.getBoundsX(i - 1) + glyphs.getBoundsWidth(i - 1) - glyphs.getBoundsX(i) + spaceBetweenGlyphs;
            double ty = 0;
            glyphs.translate(i, tx, ty);
        }
    }
}
